package com.ease.model.criterion;

import java.util.List;

import com.ease.common.vo.Entry;

/**
 * 
 * @author nathanleewei
 * 
 */
public class LogicalExpression extends CriterionSupport implements Criterion {

	/**
	 *
	 */
	private static final long serialVersionUID = -3851800630285981826L;

	private Criterion lhs;
	private Criterion rhs;
	private String op;

	/* for flex */
	public LogicalExpression() {

	}

	protected LogicalExpression(Criterion lhs, Criterion rhs, String op) {
		this.lhs = lhs;
		this.rhs = rhs;
		this.op = op;
	}

	public Criterion getLhs() {
		return lhs;
	}

	public void setLhs(Criterion lhs) {
		this.lhs = lhs;
	}

	public Criterion getRhs() {
		return rhs;
	}

	public void setRhs(Criterion rhs) {
		this.rhs = rhs;
	}

	public void setOp(String op) {
		this.op = op;
	}

	public String getOp() {
		return op;
	}

	public String toString() {
		return lhs.toString() + ' ' + getOp() + ' ' + rhs.toString();
	}

	public String toSqlString(QueryCriteria queryCriteria) {

		StringBuffer fragment = new StringBuffer();
		fragment.append("(").append(lhs.toSqlString(queryCriteria)).append(' ').append(getOp()).append(' ').append(rhs.toSqlString(queryCriteria)).append(')');
		return fragment.toString();
	}

	@SuppressWarnings("deprecation")
	public List<Entry<String, Object>> getNamedValue(QueryCriteria queryCriteria) {

		List<Entry<String, Object>> namedValue = lhs.getNamedValue(queryCriteria);
		namedValue.addAll(rhs.getNamedValue(queryCriteria));
		return namedValue;

	}

}
